﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Actuals.Business;
using Actuals.CoreDomain;
using Actuals.Common;
using Actuals.CoreDomain.Business;
using Actuals.CoreDomain.Data;



namespace Actuals
{
    public partial class CloseSprint : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
           Response.AddHeader("Cache-control","no-store , must-revalidate,private,no-cache");
            Response.AddHeader("Pragma","no-cache");
            Response.AddHeader("Expires","0");
            Response.Cache.SetCacheability(HttpCacheability.ServerAndNoCache);

            if (Session["EmployeeId"] == null)
            {
                Response.Write("Please login!");
                Response.End();
            }


           
            if (!Page.IsPostBack)
            {
                
                if(Request.QueryString["Mode"]!=null)
                {
                        string _mode = Request.QueryString["Mode"].ToString();
                        ViewState["Mode"] = _mode;
                    
                    if (_mode == "Close")
                    {
                        string _sprintId = Request.QueryString["SprintId"].ToString();
                        ViewState["SprintId"] = _sprintId;

                    }
                }
                IBusinessTechnicalTask businessTechnicalTask = new BusinessTechnicalTask();


                String _message = String.Format("Do you want to move {0} Tasks to Next Sprint", businessTechnicalTask.GetInCompleteTaskCountForSprint(int.Parse(ViewState["SprintId"].ToString())));
                lblCount.Text = _message;

                IBusinessSprint businessSprint = new BusinessSprint();
                IList<ISprint> sprints = businessSprint.GetNextSprints((int.Parse(ViewState["SprintId"].ToString()))
                                                                        ,int.Parse(Session["ProjectId"].ToString()),
                                                                         int.Parse(Session["ReleaseId"].ToString()));
                ddlNextSprint.DataSource = sprints;
                ddlNextSprint.DataTextField = "SprintDescription";
                ddlNextSprint.DataValueField = "SprintId";
                ddlNextSprint.DataBind();
                ddlNextSprint.Items.Insert(0, "Select");



                
            }

        }

        protected void InCompleteTechTaskToNextSprint()
        {
           // int sprintId = 10;
            string _nextSprint = ddlNextSprint.SelectedValue;

            
            IBusinessSprint businessSprint = new BusinessSprint();
            businessSprint.UpdateInCompleteTechTaskToNextSprint((int.Parse(ViewState["SprintId"].ToString())), int.Parse(ddlNextSprint.SelectedValue.ToString()));
            }

        protected void InCompleteTechTaskToNextSprint_Click(object sender, EventArgs e)
        {
            try
            {
                InCompleteTechTaskToNextSprint();
                lblMsg.Text = "Moved";
            }
            catch (Exception ex)
            {
                lblMsg.Text = ex.Message;
            }
        }





    }
}


